package com.heima.wemedia.controller.v1;

import com.heima.common.dtos.PageResponseResult;
import com.heima.common.dtos.ResponseResult;
import com.heima.model.wemedia.dtos.WmMaterialDto;
import com.heima.model.wemedia.pojos.WmMaterial;
import com.heima.wemedia.service.WmMaterialService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import java.util.List;

@Api("/api/v1/material")
@RestController
@RequestMapping("/api/v1/material")
public class WmMaterialController {

    @Resource
    private WmMaterialService wmMaterialService;

    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "form", dataType = "file", name = "multipartFile", value = "", required = true)
    })
    @ApiOperation(value = "", notes = "", httpMethod = "POST")
    @PostMapping("/upload_picture")
    public ResponseResult<WmMaterial> uploadPicture(@RequestParam("multipartFile") MultipartFile multipartFile) {
        return this.wmMaterialService.uploadPicture(multipartFile);
    }

    /**
     * 素材列表查询
     */

    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "body", dataType = "WmMaterialDto", name = "dto", value = "", required = true)
    })
    @ApiOperation(value = "素材列表查询", notes = "素材列表查询", httpMethod = "POST")
    @PostMapping("/list")
    public PageResponseResult<List<WmMaterial>> findList(@RequestBody WmMaterialDto dto){
        return this.wmMaterialService.findList(dto);
    }


    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "path", dataType = "int", name = "id", value = "", required = true)
    })
    @ApiOperation(value = "删除", notes = "删除", httpMethod = "GET")
    @GetMapping("del_picture/{id}")
    public ResponseResult<Void> delect(@PathVariable("id") Integer id){
        return this.wmMaterialService.delect(id);
    }

    /**
     * 取消  0无   1收藏
     */
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "path", dataType = "int", name = "id", value = "", required = true)
    })
    @ApiOperation(value = "取消  0无   1收藏", notes = "取消  0无   1收藏", httpMethod = "GET")
    @GetMapping("/cancel_collect/{id}")
    public ResponseResult<Void> cancelCollect(@PathVariable Integer id) {
        return this.wmMaterialService.cancelCollect(id);
    }

    /**
     * 收藏
     */
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "path", dataType = "int", name = "id", value = "", required = true)
    })
    @ApiOperation(value = "收藏", notes = "收藏", httpMethod = "GET")
    @GetMapping("/collect/{id}")
    public ResponseResult<Void> collect(@PathVariable Integer id) {
        return this.wmMaterialService.collect(id);
    }

}
